Repository navigation
Drawing text: lines are measured before they're set, and can break between words to fit a width (#4890) - #12349
Merged
Conversation
… to a width (tangency-labs#4890 B3b) paper_lines measures a text for paper in the drawing's font and language: its lines, each with its width, and the pitch between them, broken at each line break and, given a width, between words (a word is never cut, so a one-word line may be wider). A word the font lacks is measured in the font it falls back to. PaperLines::set only places what was measured, and paper_text is paper_lines then set, so one rule measures and sets text. Ported from the personal PC's abefb37 onto today's fallback fonts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change
Text on a drawing sheet (a dimension's number, a title block's values) is set as filled glyph outlines in the drawing's font. Until now the only way to learn how wide a line of it would be was to set it and measure the result, and a long value couldn't be broken onto more lines to fit a box. This adds one call that measures a text for paper before it's set: its lines, each with its width, and the distance between them. Given a width, it breaks the text between words so each line holds as many words as fit. Setting the text then only places what was measured, so a width and the glyphs drawn can never disagree.
Part of #4890, into
drawings. Nothing on a sheet changes yet: the title block's text uses it in a later PR.Changes a default: no
No setting, command or saved data changes; existing text on paper is set as before.
What it does
In
crates/sketch/src/paper_text.rs:paper_lines(text, family, language, height, wrap, style)measures a text: its lines, each line's width in millimetres, and the line pitch. It breaks at each line break, and withwrap(a width in millimetres) also between words. Words are the text between spaces, put back one space apart on a wrapped line. A word is never cut, so a one-word line can be wider thanwrap.PaperLines::set(at, angle)places what was measured on the sheet: its runs and the fonts they use. It doesn't measure again.paper_textis nowpaper_linesfollowed byset, so there is one rule for measuring and setting. Its results are unchanged.Validation
Local, Windows,
--profile ci, ondrawings69709bd:cargo check --all-targetsof geom, sketch, doc, io and engine; fmt; clippy-D warnings; sketchpaper_texttests: 47 passed. The same code was also checked as part of a group with the PRs that use it (dimension text, PNG text, title block text): geompaper72, iopaper45, docdrawing90, enginedrawing337,schema191, and the engine's wasm build.Tests (in
paper_text_tests.rs):setgives the same runs aspaper_textof the same lines.set, a character no font has.Planted faults, each caught by a failing test, then a clean run: wrap ignored; a line that fits exactly broken; the fallback lost when wrapping; a NaN width taken; the angle ignored at
set.Screenshots of the behavior
None: nothing on a sheet changes until a later PR uses it.
Integration status
One commit on
drawings69709bd (the latest when pushed).@0xlillith's #12039 (a label's original text kept beside its runs, for the PDF writer's text) changes the same line loop in
crates/sketch/src/paper_text.rs: it records each run's byte range in the original text as the lines are set. Whichever merges second carries the other across. With this PR the loop lives inPaperLines::set, so the ranges would be recorded there. One point for that join: a wrapped line is the text's words put back one space apart, so between two wrapped lines the original text has spaces, not a line break. #12039's check allows only line breaks between runs, so a wrapped value would need its ranges taken from the words, or the check would need to allow the spaces a wrap removed. Nothing wraps on a sheet until the title block text PR (#12357), and #12039's PDF reader comes later, so it can be settled when the two meet.